package com.curry.apiprovider.service.quartz;

import com.curry.apiprovider.crawler.Constants;
import com.curry.apiprovider.generator.mapper.TCityInfoMapper;
import com.curry.apiprovider.service.CrawlerWrapperService;
import com.curry.apiprovider.util.StringUtils;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class QcJobTask implements IJobTask {
    private Logger logger = LoggerFactory.getLogger(QcJobTask.class);


    private TCityInfoMapper tCityInfoMapper;
    private CrawlerWrapperService crawlerWrapperService;

    public QcJobTask(TCityInfoMapper tCityInfoMapper, CrawlerWrapperService crawlerWrapperService) {
        this.tCityInfoMapper = tCityInfoMapper;
        this.crawlerWrapperService = crawlerWrapperService;
    }

    @Override
    public void executeTask(Map<String, Object> params) {
        logger.warn("executeTask   " + params.toString());
        String  keyWord = (String) params.get("keyWord");
        String cityName = (String) params.get("cityName");
        String cityCode = tCityInfoMapper.getCityCodeByCityName(params);
        String[] pageParams = new String[]{cityCode, keyWord, "1"};
//        int jobTotalPage = crawlerWrapperService.getJobTotalPage(StringUtils.replaceAll(pageParams, Constants.JOB_URL), pageParams);
//        logger.warn("excuteTask   " + jobTotalPage);
//        for (int i = 0; i < 1; i++) {
//            String[] jobParams = new String[]{cityCode, keyWord, String.valueOf(i + 1)};
//            crawlerWrapperService.startJobCrawler(StringUtils.replaceAll(jobParams, Constants.JOB_URL), jobParams);
//        }
    }
}
